﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SecurityLib;
namespace QuanLyDeTaiKHCN.Obj_class
{
    public class MemberShip_ASP
    {
        public class DSCanBo
        {
            public int ID { get; set; }
            public string HoTen { get; set; }
            public string DonVi { get; set; }
            public string HocHam { get; set; }
        }
        public class Temp
        {
            public string MaDeTaiDuAn { get; set; }
            public string TenDeTaiDuAn { get; set; }
            public string NguoiThuLy { get; set; }
            public string Ngay { get; set; }
            public bool Tre { get; set; }
            public bool  TreDeTai { get; set; }
        }
        public class XepLoais
        {
            public string ID { get; set; }
            public string XepLoai { get; set; }
        }
        public static List<XepLoais> GetXepLoai()
        {
            List<XepLoais> list = new List<XepLoais>()
            {
                new XepLoais(){ID="-1",XepLoai="---Xếp loại---"},
                new XepLoais(){ID="1",XepLoai="Không đạt"},
                new XepLoais(){ID="2",XepLoai="Trung bình"},
                new XepLoais(){ID="3",XepLoai="Khá"},
                new XepLoais(){ID="4",XepLoai="Xuất sắc"}
            };
            return list;
        }
        public static string madetaiduan { get; set; }
        public static List<tblHoiDongKhoaHoc> listmember { get; set; }
        public static List<tblDanhMuc> listdanhmuc { get; set; }
        public static List<DSCanBo> listDS = new List<DSCanBo>();
        public static List<Temp> dsdetai { get; set; }
        public static List<string> listThoiGianThucHienDen { get; set; }
        public static List<int> listgiaidoanthuchien { get; set; }
        public static string[] GetRoles(string UserName)
        {
            _dbDataContext _db = new _dbDataContext();
            var tablerole = from p in _db.tblUserInRoles
                            where p.tblAcount.TenDangNhap.ToString().Trim().ToUpper() == UserName.ToUpper()
                            select new
                            {
                                rolename = p.tblRole.RoleName.ToString().Trim()
                            };
            string[] Roles = new string[tablerole.ToList().Count];
            int i = 0;
            foreach (var role in tablerole)
            {
                Roles[i] = role.rolename.ToString().Trim();
                i++;
            }
            return Roles;
        }
        public static bool Login(string UserName, string Password)
        {
            _dbDataContext data = new _dbDataContext();
            PasswordHasherEncrypt passhasher = new PasswordHasherEncrypt();
            var login = from p in data.tblAcounts
                        where (p.TenDangNhap.ToString().Trim().ToUpper() == UserName.ToUpper() && p.MatKhau.Trim() == passhasher.Hash_SHA1(passhasher.EncryptPassword_MD5(Password)) && p.PhanQuyen == true)
                        select p;
            if (login.ToList().Count > 0)
                return true;
            else
                return false;
        }
        public static string GetTenHienThi(string username)
        {
            _dbDataContext _db = new _dbDataContext();
            return _db.tblAcounts.Single(r => r.TenDangNhap.Trim().ToUpper() == username.Trim().ToUpper()).TenHienThi.Trim();
        }
        public static string GetOldPass(string username)
        {
            _dbDataContext _db = new _dbDataContext();
            return _db.tblAcounts.Single(r => r.TenDangNhap.Trim().ToUpper() == username.Trim().ToUpper()).MatKhau.Trim();
        }
        public static bool ChangePass(string username, string pass)
        {
            _dbDataContext _db = new _dbDataContext();
            var val = _db.tblAcounts.Single(r => r.TenDangNhap.Trim().ToUpper() == username.Trim().ToUpper());
            val.MatKhau = pass;
            try
            {
                _db.SubmitChanges();
                return true;
            }
            catch { return false; }
        }
    }
}